//
//  TickectVC.m
//  ImGuider
//
//  Created by 王鹏宇 on 2017/12/28.
//  Copyright © 2017年 imguider. All rights reserved.
//

#import "TickectVC.h"
#import "TicketCell.h"
#import "TickectDetailVC.h"
@interface TickectVC ()<UITableViewDelegate,UITableViewDataSource>

@property (weak, nonatomic) IBOutlet UITableView *tableView;

@property (nonatomic, strong)NSArray * dataSource;
@end

@implementation TickectVC

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    
    self.title = MYLocalizedString(@"TICKET_TITLE", nil);
    [self.tableView registerNib:[UINib nibWithNibName:@"TicketCell" bundle:nil] forCellReuseIdentifier:@"TicketCell"];
    
    self.view.backgroundColor = kBGColor;
    self.tableView.backgroundColor = kBGColor;
    [self loadData];
}



- (void)loadData {
    
    [ActivityIndicatorView showHUDAddedTo:self.view];
    
    [NetAPIManager getTicketListWithCityID:self.cityID block:^(NSArray *TicketList, NSError *error) {
        [ActivityIndicatorView hideHUDAddedTo:self.view];
        self.dataSource = [NSArray arrayWithArray:TicketList];
         [self.tableView reloadData];
    }];
}



#pragma mark    ---UITableViewDelegate,UITableViewDataSource


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    
    return self.dataSource.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    
    TicketCell * cell = [tableView dequeueReusableCellWithIdentifier:@"TicketCell"];
    
    TicketModel * ticketModel = self.dataSource[indexPath.row];
    cell.ticket = ticketModel;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    TickectDetailVC * vc = [[TickectDetailVC alloc] init];
    
    TicketModel * ticket = self.dataSource[indexPath.row];
    
    vc.ticketID = ticket.tid;
    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
